package org.lex.dbq.view.driver;

import java.io.File;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Shell;
import org.lex.dbq.util.DialogUtils;

public class AddHandler extends DriverActionHandler {
	private final boolean file;

	public AddHandler(DriverDialog dialog, boolean file) {
		super(dialog);
		this.file = file;
	}

	@Override
	public void widgetSelected(SelectionEvent e) {
		File[] files = null;
		Shell shell = dialog.getShell();
		if (true == file) {
			files = DialogUtils.chooseFiles(shell, SWT.MULTI | SWT.OPEN, new String[] { "*.jar", "*.zip" });
		} else {
			File file = DialogUtils.chooseDirectory(shell, "dir");
			if (null != file) {
				files = new File[] { file };
			}
		}
		if (null != files) {
			dialog.addClasspath(files);
		}
	}
}
